<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="发货单号" prop="waybillNo">
        <el-input v-model="queryParams.waybillNo" placeholder="请输入发货单号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="项目" prop="projectNo">
        <el-select v-model="queryParams.projectNo" filterable allow-create @keyup.enter.native="handleQuery"
          default-first-option placeholder="发货计划号">
          <el-option v-for="item in projectName1" :key="item.value" :label="item.projectNo" :value="item.projectNo">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="栋号" prop="buildNo">
        <el-select v-model="queryParams.buildNo" filterable allow-create @keyup.enter.native="handleQuery"
          default-first-option placeholder="发货计划号">
          <el-option v-for="item in buildLou" :key="item.value" :label="item.buildNo" :value="item.buildNo">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="楼层" prop="floor">
        <el-input-number v-model="queryParams.beginFloor" controls-position="right" @change="handleChange" :min="0">
        </el-input-number>至
        <el-input-number v-model="queryParams.endFloor" controls-position="right" @change="handleChange" :min="0">
        </el-input-number>
      </el-form-item>
      <el-form-item label="审批状态" prop="approvalStatus">
        <el-select v-model="queryParams.approvalStatus" placeholder="请选择审批状态(0未审核 1通过 2驳回)" clearable>
          <el-option v-for="dict in dict.type.waybill_status" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="物流公司" prop="transportUnit">
        <el-input v-model="queryParams.transportUnit" placeholder="请输入运输单位" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="物流公司" prop="compomentName">
        <el-input v-model="queryParams.compomentName" placeholder="请输入运输单位" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="车牌号" prop="carNo">
        <el-input v-model="queryParams.carNo" placeholder="请输入车牌号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="创建时间">
        <el-date-picker v-model="daterangeCreateTime" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:info:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />

      <el-table-column label="发货计划号" align="center" prop="deliveryPlanNo" />

      <el-table-column label="发货单号" align="center" prop="waybillNo" />
      <el-table-column label="审批状态" align="center" prop="approvalStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.waybill_status" :value="scope.row.approvalStatus" />
        </template>
      </el-table-column>
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="楼栋" align="center" prop="buildNo" />
      <el-table-column label="楼层" align="center" prop="floor" />
      <el-table-column label="构件类型" align="center" prop="compomentType" />
      <el-table-column label="构件总数量" align="center" prop="totalCount" />
      <el-table-column label="构件总重量" align="center" prop="totalWeight" />
      <!-- <el-table-column label="出库时间" align="center" prop="waybillTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.waybillTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="联系人" align="center" prop="contacts" /> -->
      <!-- <el-table-column label="联系电话" align="center" prop="contact" /> -->
      <el-table-column label="审批时间" align="center" prop="approvalTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.approvalTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审批人" align="center" prop="approval" />
      <el-table-column label="打印时间" align="center" prop="printTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.printTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="司机" align="center" prop="driver" />
      <el-table-column label="车牌号" align="center" prop="carNo" />
      <el-table-column label="收货状态" align="center" prop="receivingStatus" />
      <el-table-column label="收货人" align="center" prop="receivingUser" />
      <el-table-column label="收货时间" align="center" prop="receivingTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.receivingTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <!-- <el-table-column label="仓库名称" align="center" prop="warehouseName" />
      <el-table-column label="仓库区域" align="center" prop="warehouseArea" />
      <el-table-column label="客户" align="center" prop="customer" />-->
      <el-table-column label="物流公司" align="center" prop="transportUnit" />
      <!-- <el-table-column label="运输方式" align="center" prop="transportType" /> -->
      <!-- <el-table-column label="制单人" align="center" prop="producer" /> -->


      <!--       
      <el-table-column label="发货员" align="center" prop="consignor" /> -->


      <!-- <el-table-column label="是否打印" align="center" prop="isPrint" /> -->

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="print(scope.row)"
            v-hasPermi="['system:info:edit']">打印</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['system:info:remove']">删除</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="transit(scope.row)"
            v-hasPermi="['system:info:remove']">通过</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="turnDown(scope.row)"
            v-hasPermi="['system:info:remove']">驳回</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改发运单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="项目编号" prop="projectNo">
          <el-input v-model="form.projectNo" placeholder="请输入项目编号" />
        </el-form-item>
        <el-form-item label="发货单号" prop="waybillNo">
          <el-input v-model="form.waybillNo" placeholder="请输入发货单号" />
        </el-form-item>
        <el-form-item label="出库时间" prop="waybillTime">
          <el-date-picker clearable v-model="form.waybillTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择出库时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="联系人" prop="contacts">
          <el-input v-model="form.contacts" placeholder="请输入联系人" />
        </el-form-item>
        <el-form-item label="联系电话" prop="contact">
          <el-input v-model="form.contact" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="栋号" prop="buildNo">
          <el-input v-model="form.buildNo" placeholder="请输入栋号" />
        </el-form-item>
        <el-form-item label="楼层" prop="floor">
          <el-input v-model="form.floor" placeholder="请输入楼层" />
        </el-form-item>
        <el-form-item label="仓库名称" prop="warehouseName">
          <el-input v-model="form.warehouseName" placeholder="请输入仓库名称" />
        </el-form-item>
        <el-form-item label="仓库区域" prop="warehouseArea">
          <el-input v-model="form.warehouseArea" placeholder="请输入仓库区域" />
        </el-form-item>
        <el-form-item label="客户" prop="customer">
          <el-input v-model="form.customer" placeholder="请输入客户" />
        </el-form-item>
        <el-form-item label="运输单位" prop="transportUnit">
          <el-input v-model="form.transportUnit" placeholder="请输入运输单位" />
        </el-form-item>
        <el-form-item label="车牌号码" prop="carNo">
          <el-input v-model="form.carNo" placeholder="请输入车牌号码" />
        </el-form-item>
        <el-form-item label="制单人" prop="producer">
          <el-input v-model="form.producer" placeholder="请输入制单人" />
        </el-form-item>
        <el-form-item label="审批状态(0未审核 1通过 2驳回)" prop="approvalStatus">
          <el-select v-model="form.approvalStatus" placeholder="请选择审批状态(0未审核 1通过 2驳回)">
            <el-option v-for="dict in dict.type.waybill_status" :key="dict.value" :label="dict.label"
              :value="parseInt(dict.value)"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审批时间" prop="approvalTime">
          <el-date-picker clearable v-model="form.approvalTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择审批时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="审批人" prop="approval">
          <el-input v-model="form.approval" placeholder="请输入审批人" />
        </el-form-item>
        <el-form-item label="发货员" prop="consignor">
          <el-input v-model="form.consignor" placeholder="请输入发货员" />
        </el-form-item>
        <el-form-item label="司机" prop="driver">
          <el-input v-model="form.driver" placeholder="请输入司机" />
        </el-form-item>
        <el-form-item label="收货人" prop="receivingUser">
          <el-input v-model="form.receivingUser" placeholder="请输入收货人" />
        </el-form-item>
        <el-form-item label="收货时间" prop="receivingTime">
          <el-date-picker clearable v-model="form.receivingTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择收货时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="是否打印" prop="isPrint">
          <el-input v-model="form.isPrint" placeholder="请输入是否打印" />
        </el-form-item>
        <el-form-item label="打印时间" prop="printTime">
          <el-date-picker clearable v-model="form.printTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择打印时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo, trunToExamine,mimeographList } from "@/api/yard/WaybillInfo";

export default {
  name: "Info",
  dicts: ['waybill_status'],
  data() {
    return {
      // 项目
      projectName1: [],
      // 楼栋
      buildLou: [],
      // 楼层
      floorLc: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 发运单表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 打印时间时间范围
      daterangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectNo: null,
        transportUnit: null,
        totalCount: null,
        totalWeight: null,

        deliveryPlanNo: null,
        beginFloor: null,
        waybillNo: null,
        buildNo: null,
        floor: null,
        transportUnit: null,
        carNo: null,
        createBy: null,
        compomentName: null,
        compomentType: null,
        approvalStatus: null,
        createTime: null,
        endFloor: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询发运单列表 */
    getList() {

      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
        for (let i = 0; i < response.rows.length; i++) {
          // this.projectName1 = response.rows[i].projectNo
          this.projectName1 = response.rows
          // this.projectName1 = response.rows[i].projectNo
          this.buildLou = response.rows
          this.floorLc = response.rows
        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        projectNo: null,
        deliveryPlanNo: null,
        waybillNo: null,
        waybillTime: null,
        contacts: null,
        contact: null,
        buildNo: null,
        floor: null,
        warehouseName: null,
        warehouseArea: null,
        customer: null,
        transportUnit: null,
        transportType: null,
        carNo: null,
        producer: null,
        approvalStatus: null,
        compomentName: null,
        approvalTime: null,
        compomentType: null,
        approval: null,
        consignor: null,
        driver: null,
        transportUnit: null,
        receivingUser: null,
        receivingStatus: 0,
        receivingTime: null,
        isPrint: null,
        printTime: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        totalCount: null,
        totalWeight: null,
        createBy: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加发运单";
    },
    /** 打印按钮操作 */
    print(row) {
      mimeographList(row.id).then(res=>{

      })
      this.$router.push({ path: "/WaybillInfo/print",query:{id:row.id} })
    },
    /** 通过按钮操作 */
    transit(row) {
      trunToExamine({
        "id": row.id,
        "state": 1,
      }).then(res=>{

      })
    },
    /** 驳回按钮操作 */
    turnDown(row) {
      trunToExamine({
        "id": row.id,
        "state": 2,
      }).then(res=>{
        
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除发运单编号为"' + ids + '"的数据项？').then(function () {
        return delInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/info/export', {
        ...this.queryParams
      }, `info_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
